
<?php

$id = !empty($_GET['id'])?$_GET['id']:''; //获取地址栏中参数名是id的值


if(!empty($_POST)){


  if(empty($_POST['npassword']) || empty($_POST['cpassword']) || empty($_POST['password'])){
    echo"<script>alert('原始密码、新密码或确认密码不能为空');history.go(-1)</script>";die;
  }

  $password = md5($_POST['password']);
  $npassword = md5($_POST['npassword']);
  $cpassword = md5($_POST['cpassword']);

   // 判断密码输入是否一致（实现确认密码）
  if($npassword!=$cpassword){
     echo"<script>alert('新密码不一致');history.go(-1)</script>";die;
  }


   //查询输入的密码与数据库的密码是否一致
/*  $sql = "select * from `admin` where `id`=$id";

  //执行语句
  $result = mysqli_query($link,$sql);

  $passwords = mysqli_fetch_assoc($result)['password'];
*/
  $passwords = getSelectByOne('admin',"id=$id")['password'];

  // 判断密码输入是否一致（实现确认密码）
  if($password!=$passwords){
    echo"<script>alert('原始密码错误');history.go(-1)</script>";die;
  }





  //修改语句
  //update `v9_linkage` set style = 0 where linkageid = 22
/*  $sql = " update `admin` set `password`='$npassword' where `id`=$id";

  //执行语句
  mysqli_query($link,$sql);
  //提取真值
  $_rows = mysqli_affected_rows($link);*/  //-1   0   1
  $data['password']=$npassword;
  $_rows = edit('admin',$id,$data);

  if($_rows>=0){
     echo"<script>alert('密码修改成功');location.href='index.php?c=admin&a=list&admin=1'</script>";die;
  }else{
     echo"<script>alert('密码修改失败');history.go(-1)</script>";die;
  }

}
 //查询语句
/*  $sql = "select * from `admin` where `id`=$id";

  //执行语句
  $result = mysqli_query($link,$sql);

  $data = mysqli_fetch_assoc($result);*/

  $data = getSelectByOne('admin',"id=$id");

//加载后台公共视图
 include (View_PATH.$admin.'/communal.html');


?>

